﻿
using System;
using System.Data;
using System.Collections.Generic;

namespace LDSP.BRL
{
    public partial class Plan : BYFW.BOL.BaseEntity
    {
        public Plan()
        {
            m_tableName = "t_plan";
            m_hasName = true;
            m_hasComment = true;
            m_tblCacheManager.IsEnable = true;
        }

        protected string m_person = string.Empty;
        protected DateTime m_expiredDT = DateTime.Now;
        protected int m_favoriteID = 0;
        protected int m_status = 0;
        protected string m_department = string.Empty;
        protected string m_progress = string.Empty;
        protected DateTime m_changeDT = DateTime.Now;

        protected R_EnterpriseCodification m_enterpriseCodification = null;

        /// <summary>
        /// 相关人员
        /// </summary>
        public string Person
        {
            get { return m_person; }
            set { m_person = value; }
        }
        /// <summary>
        /// 到期时间
        /// </summary>
        public DateTime ExpiredDT
        {
            get { return m_expiredDT; }
            set { m_expiredDT = value; }
        }
        /// <summary>
        /// 收藏关系ID
        /// </summary>
        public int FavoriteID
        {
            get { return m_favoriteID; }
            set { m_favoriteID = value; }
        }
        /// <summary>
        /// 状态
        /// </summary>
        public int Status
        {
            get { return m_status; }
            set { m_status = value; }
        }
        /// <summary>
        /// 部门/人员
        /// </summary>
        public string Department
        {
            get { return m_department; }
            set { m_department = value; }
        }
        /// <summary>
        /// 项目进度概述
        /// </summary>
        public string Progress
        {
            get { return m_progress; }
            set { m_progress = value; }
        }
        /// <summary>
        /// 修改时间
        /// </summary>
        public DateTime ChangeDT
        {
            get { return m_changeDT; }
            set { m_changeDT = value; }
        }


        public R_EnterpriseCodification EnterpriseCodification
        {
            get
            {
                if (m_enterpriseCodification == null)
                {
                    m_enterpriseCodification = new R_EnterpriseCodification();
                    if (m_favoriteID != 0)
                    {
                        m_enterpriseCodification.GetProperties(m_favoriteID);
                    }
                }
                return m_enterpriseCodification;
            }
        }

        protected override void FillContainer()
        {
            base.FillContainer();
            m_container.Add("person", m_person);
            m_container.Add("expiredDT", m_expiredDT);
            m_container.Add("favoriteID", m_favoriteID);
            m_container.Add("status", m_status);
            m_container.Add("department", m_department);
            m_container.Add("progress", m_progress);
            m_container.Add("changeDT", m_changeDT);
        }

        public override bool GetProperties(System.Data.DataRow record)
        {
            if (!base.GetProperties(record))
            {
                return false;
            }
            m_person = this.GetStringValue(record, "person");
            m_expiredDT = this.GetDateValue(record, "expiredDT");
            m_favoriteID = this.GetIntValue(record, "favoriteID");
            m_status = this.GetIntValue(record, "status");
            m_department = this.GetStringValue(record, "department");
            m_progress = this.GetStringValue(record, "progress");
            m_changeDT = this.GetDateValue(record, "changeDT");
            return true;
        }

        public void DeleteByCodification(string transID, int favoriteID)
        {
            string cond = string.Format("where {0}={1}", DB.GetCol("favoriteID"), DB.GetVal(favoriteID));
            this.DeleteRecord(transID, cond);
        }

        public DataTable GetRecordsByEnterprise(int enterpriseID, string cond)
        {
            string select = @"select * from (select t_plan.* from t_plan, t_r_enterprise_codification t1 where t_plan.favoriteID = t1.id and t1.enterpriseID = {0}) t";
            string sql = string.Empty;

            if (cond.Length > 0)
            {
                sql = string.Format(select + " {1} ", enterpriseID, cond);
            }
            else
            {
                sql = string.Format(select, enterpriseID);
            }

            return this.DB.Select(sql).Tables[0];
        }
    }
}

